package cn.itcast.controller;

import cn.itcast.domain.Account;
import cn.itcast.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @GetMapping("/find")
    public Object findAll()throws Exception{
        List<Account> list = accountService.findAll();
        return list;
    }

    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id)throws Exception{
       return accountService.findById(id);
    }

    @PostMapping("/add")
    public Object add(@RequestBody Account account)throws Exception{
        accountService.add(account);
        return "success";
    }

    @PutMapping("/update")
    public Object update(@RequestBody Account account)throws Exception{
        accountService.update(account);
        return "success";
    }

    @DeleteMapping("/delete/{id}")
    public Object delete(@PathVariable Integer id)throws Exception{
        accountService.delete(id);
        return "success";
    }
}
